package cuongnh.project.japanesediary.vocabulary.ui.handler.command;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IWorkbenchWizard;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.wizards.IWizardDescriptor;

public class NewGrammar extends AbstractHandler {

	public static final String ID = "cuongnh.project.japanesediary.vocabulary.command.newGrammar";
	
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWizardDescriptor desc = PlatformUI
				.getWorkbench()
				.getNewWizardRegistry()
				.findWizard(
						"cuongnh.project.japanesediary.vocabulary.wizard.newGrammarWizard");
		try {
			IWorkbenchWizard wiz = desc.createWizard();
			wiz.init(PlatformUI.getWorkbench(),
					(IStructuredSelection) HandlerUtil
							.getActiveMenuSelection(event));
			WizardDialog dialog = new WizardDialog(
					HandlerUtil.getActiveShellChecked(event), wiz);
			dialog.create();
			dialog.getShell().setSize(dialog.getShell().getSize().x,
					dialog.getShell().getSize().y);
			dialog.open();
		} catch (CoreException e) {
			e.printStackTrace();
		}
		return null;
	}

}
